//
//  CPCombinationCell.m
//  CPApp
//
//  Created by yobet on 2018/3/22.
//  Copyright © 2018年 Class. All rights reserved.
//

#import "CPCombinationCell.h"
#import "CPColorMessageModel.h"
@interface CPCombinationCell ()
@property (weak, nonatomic) IBOutlet UILabel *zhuanjia;
@property(nonatomic,strong) NSMutableArray * arrangMutableArr;
@end
@implementation CPCombinationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.zhuanjia.layer.borderWidth = 1;
    self.zhuanjia.layer.borderColor = HJColor(249, 137, 138).CGColor;
    
    self.hitnum.layer.borderWidth = 1;
    self.hitnum.layer.borderColor = HJColor(249, 137, 138).CGColor;
}
-(NSMutableArray *)arrangMutableArr {
    if (!_arrangMutableArr) {
        _arrangMutableArr =[NSMutableArray array];
    }
    return _arrangMutableArr;
}
-(void)setModel:(CPColorMessageModel *)model {
    _model = model;
    self.username.text = model.username;
    self.hitnum.text = model.hitnum;
    self.award.text = model.award;
    self.viewnum.text = model.viewnum;
    
    
    NSArray * arr = [model.calc componentsSeparatedByString:@","];
    for (int i =0; i<arr.count; i++) {
        UILabel * label = [self configLabelWithIndex:i];
        label.text = arr[i];
        label.hidden = NO;
    }
    for (NSInteger j = arr.count; j<self.arrangMutableArr.count; j++) {
        UILabel * label = [self configLabelWithIndex:j];
        label.hidden = YES;
    }
    [self setNeedsLayout];
    
}

-(UILabel *)configLabelWithIndex:(NSInteger)index {
    UILabel * label;
    if (index<self.arrangMutableArr.count) {
        label = self.arrangMutableArr[index];
    }else {
        label = [UILabel new];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:13];
        label.textAlignment = NSTextAlignmentCenter;
        label.tag = index;
        label.layer.masksToBounds = YES;
        label.layer.cornerRadius = 15;
        label.backgroundColor = HJColor(240, 8, 7);
        [self.arrangMutableArr addObject:label];
        [self.calc addSubview:label];
    }
    return label;
}
-(void)layoutSubviews {
    [super layoutSubviews];
    float W = 30;
    for (int i = 0; i<self.arrangMutableArr.count; i++) {
        UILabel *label = [self configLabelWithIndex:i];
        label.frame = CGRectMake(i*(W + 5), 0, W, W);
    }
}
@end
